<?php
/**
 * 创建缺失的必要表
 */
require_once __DIR__ . '/../vendor/autoload.php';

use think\facade\Db;

// 读取SQL文件
$sqlFile = __DIR__ . '/create_missing_tables.sql';
$sqlContent = file_get_contents($sqlFile);

if (!$sqlContent) {
    echo "❌ 无法读取SQL文件\n";
    exit(1);
}

try {
    // 执行SQL语句
    Db::execute($sqlContent);
    echo "✅ 缺失的表创建成功\n";
    
    // 验证表是否创建成功
    $tables = Db::query("SHOW TABLES LIKE 'gf_data_exports'");
    if (empty($tables)) {
        echo "⚠️  gf_data_exports表未创建成功\n";
    } else {
        echo "✅ gf_data_exports表创建成功\n";
    }
    
    $tables = Db::query("SHOW TABLES LIKE 'gf_antifraud_high_risk'");
    if (empty($tables)) {
        echo "⚠️  gf_antifraud_high_risk表未创建成功\n";
    } else {
        echo "✅ gf_antifraud_high_risk表创建成功\n";
    }
    
} catch (\Exception $e) {
    echo "❌ 创建表失败: " . $e->getMessage() . "\n";
    exit(1);
}